<?php
namespace app\common\library;
/**
 * @author 河南邦耀网络科技
 * @copyright Copyright (c) 2018 HNBY Network Technology Co., Ltd.
 * @link http://www.hnbangyao.com
 */
class Shorturl
{
    CONST APPKEY = "061E06363634C38174A29BF72DE61671";

    /**
     * 长链转短链
     * @param $longUrl
     * @return string
     */
    public static function create($longUrl)
    {
        $params = [
            'appkey' => self::APPKEY,
            'url'     => $longUrl,
        ];

        $result = \fast\Http::get('http://api.monkeyapi.com?'. http_build_query($params));
        $content = json_decode($result,true);
        if(empty($content['code']) || $content['code'] != 200){
            return $longUrl;
        }
        return $content['data'] ?? '';
    }
}
